<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Minim : : EnvelopeFollower</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body> 
<center>
<table class="mainTable">
  <tr>
    <td class="header">
    	<span class="indexheader">Minim</span><br/>
    	<span class="indexnavigation">
    		<a href="index.html">core</a> | 
    		<a href="index_ugens.html">ugens</a> | 
    		<a href="index_analysis.html">analysis</a>
    	</span>
    </td>
    <td class="border-left">&nbsp;</td>
  </tr>
  
  <tr>
    <td class="classNavigation">
    	<p class="mainTextName">EnvelopeFollower</p>
    	
       <p class="linkListHeader">Fields</p>
       <p class="linkList">
           
    <a href="envelopefollower_field_audio.html" title="Where incoming audio is patched.">audio</a><br/>
    
	   </p>
   
    	
       <p class="linkListHeader">Methods</p>
       <p class="linkList">
           
    <a href="envelopefollower_method_channelcount.html" title="Returns the number of channels this UGen has been configured to generate.">channelCount ( )</a><br/>
    
    <a href="envelopefollower_method_getlastvalues.html" title="Return the last values generated by this UGen. This will most often be
 used by sub-classes when pulling data from their inputs.">getLastValues ( )</a><br/>
    
    <a href="envelopefollower_method_patch.html" title="Send the output of this UGen to another UGen, UGenInput, or AudioOutput.">patch ( )</a><br/>
    
    <a href="envelopefollower_method_printinputs.html" title="Prints all inputs connected to this UGen (for debugging)">printInputs ( )</a><br/>
    
    <a href="envelopefollower_method_samplerate.html" title="Returns the sample rate of this UGen.">sampleRate ( )</a><br/>
    
    <a href="envelopefollower_method_setchannelcount.html" title="Let this UGen know how many channels of audio you will be asking it for.">setChannelCount ( )</a><br/>
    
    <a href="envelopefollower_method_setsamplerate.html" title="Set the sample rate for this UGen.">setSampleRate ( )</a><br/>
    
    <a href="envelopefollower_method_tick.html" title="Generates one sample frame for this UGen.">tick ( )</a><br/>
    
    <a href="envelopefollower_method_unpatch.html" title="Unpatch this UGen from an AudioOutput or other UGen.">unpatch ( )</a><br/>
    
	   </p>
   
    </td>
    <td class="mainText border-left">
    	An EnvelopeFollower will analyze the audio coming into it and output a value that reflects 
 the volume level of that audio. It is similar to what AudioBuffer's level method provides, 
 but has the advantage of being able to be inserted into the signal chain anywhere.
 
 You may find that you are only interested in the output value of the EnvelopeFollower for 
 visualization purposes, in which case you can use a Sink UGen to tick the EnvelopeFollower
 without generating any sound. The following example demonstrates this technique.
 
 We still consider EnveloperFollower to be a bit experimental, so YMMV.
    	<p class="memberSectionHeader">Constructors</p>
    	<pre><em>Construct an EnvelopeFollower.</em>
EnvelopeFollower(float attackInSeconds, float releaseInSeconds, int bufferSize)
</pre>
    	
   <p class="memberSectionHeader">Parameters</p>
   
        <span class="parameterName">attackInSeconds</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">float: how many seconds the follower should take to ramp up to a higher value</span><br/>
    
        <span class="parameterName">releaseInSeconds</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">float: how many seconds the follower should take to ramp down to a lower value</span><br/>
    
        <span class="parameterName">bufferSize</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">int: how many samples should be analyzed at once. smaller buffers will make
 				 the follower more responsive.</span><br/>
    
   
    	<p class="memberSectionHeader">Related</p>
    	<A href="ugen_class_ugen.html">UGen</A><BR>

    	<p class="memberSectionHeader">Example</p>
    	<pre>/**
  * This sketch demonstrates how to use an EnvelopeFollower, which will 
  * analyze the audio coming into it and output a value that reflects 
  * the volume level of that audio. It is similar to what AudioBuffer's 
  * level method provides, but has the advantage of being able to be 
  * inserted into the signal chain anywhere.
  * &lt;p>
  * This sketch also demonstrates using a Sink UGen, which can have 
  * many UGens patched to it, like a Summer, but that generates silence.
  * It is used here because we need a way to tick the EnvelopeFollower
  * but we are not interested in hearing the output of the EnvelopeFollower.
  * &lt;p>
  * For more information about Minim and additional features,&lt;br/>
  * visit http://code.compartmental.net/minim/
  */

import ddf.minim.*;
import ddf.minim.ugens.*;

Minim             minim;
AudioOutput       out;
Oscil             wave;
Oscil             mod;
EnvelopeFollower envFollow;

void setup()
{
  size(512, 200, P3D);
  
  minim = new Minim(this);
  
  // use the getLineOut method of the Minim object to get an AudioOutput object
  out = minim.getLineOut();
  
  // create a triangle wave Oscil, set to 440 Hz, at 1.0 amplitude
  // in this case, the amplitude we construct the Oscil with 
  // doesn't matter because we will be patching something to
  // its amplitude input.
  wave = new Oscil( 440, 1.0f, Waves.TRIANGLE );
 
  // create a sine wave Oscil for modulating the amplitude of wave
  mod  = new Oscil( 2, 0.4f, Waves.SINE );
 
  // connect up the modulator
  mod.patch( wave.amplitude );
  
  // patch wave to the output
  wave.patch( out );
  
  // now create an envelope follower to show the level of the wave
  
  envFollow = new EnvelopeFollower( 0,   // attack time in seconds
                                    0.1, // release time in seconds
                                    1024 // size of buffer to analyze 
                                  );
  
  // a sink to tick the envelope follower because 
  // we won't use the output of it in the signal chain
  Sink sink = new Sink();
  wave.patch( envFollow ).patch( sink ).patch( out );
}

void draw()
{
  // adjust the modulator amplitude based on mouseY
  // this should mean that when the modulator has 
  // a high amplitude that the envelope follower 
  // will report a larger range of values
  float amp = constrain( map( mouseY, 0, height, 1, 0), 0, 1 );
  mod.amplitude.setLastValue( amp );
  
  // and we can connect the frequency of modulation to mouseX
  // and see the result of that in the follower, as well
  float freq = constrain( map( mouseX, 0, width, 0.1, 1 ), 0.1, 1 );
  mod.frequency.setLastValue( freq );
  
  background(0);
  stroke(0);
  fill(255);
  
  // draw the output of the envelope follower
  float h = envFollow.getLastValues()[0] * height;
  rect( 0, height - h, width, height );
}
</pre>
    	<p class="memberSectionHeader">Usage</p>
    	Web & Application
    </td>
  </tr>
</table>
</center>
</body>
</html>